package com.corticon.dialogs.validation.designer;

/**
 * server validator in create/update question
 */

import com.corticon.dialogs.model.Question;
import com.corticon.dialogs.validation.GenericHibernateValidator;
import com.corticon.dialogs.validation.ValidationMessageFormatter;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.springframework.validation.Errors;

public class QuestionValidator extends GenericHibernateValidator<Question> {

    public QuestionValidator(
            ValidationMessageFormatter validationMessageFormatter) {
        super.validationMessageFormatter = validationMessageFormatter;
    }

    @Override
    protected void complexValidate(Object object, Errors errors) {
        super.complexValidate(object, errors);

        Question validator = (Question) object;

        List<Character> vocabularyExcludedChars = new ArrayList<Character>();
        vocabularyExcludedChars.add('_');

        String[] nameArgs = {"Name"};
        commonCharactersValidate(validator.getName(), vocabularyExcludedChars,
                errors, "name", "questionBase.validate.name.invalidChars",
                nameArgs, "default message");
        String[] nameArgs1 = {"Vacabularyname"};
        commonCharactersValidate(validator.getVocabularyname(), vocabularyExcludedChars,
                errors, "vocabularyname", "questionBase.validate.vacabularyname.invalidChars",
                nameArgs1, "default message");
      
        if (StringUtils.isEmpty(validator.getText())){
            errors.rejectValue("text", "questionBase.validate.text.required",
                    "default message");
        }    
    }
}
